{% extends "base.html" %}
{% load pretty_user %}
{% load match %}
{% load partial_template %}

{% block additional_title %}
Tabela igrača
{% endblock %}

{% block additional_head %}	
	<script type="text/javascript" src="/mdcs/media/js/TableSorter/jquery.tablesorter.min.js"></script>

	<script type="text/javascript" id="js" language="javascript">
		var extraction = function(node) {
			if (node.id.indexOf('id') == 0) {
				var position = node.innerHTML;
				return position.substring(0, position.length-1);
			} else if (node.id.indexOf('user') == 0) {
				return node.childNodes[0].childNodes[0].nodeValue;
			} else {
				return node.childNodes[0].nodeValue;
			}
		}
		$(document).ready(function() {
			$("#mainTable").tablesorter( {textExtraction: extraction} );
		})
	</script>
{% endblock %}

{% block nav %}
{% partial_template navigation.html selected_tab:"standings" user:user perms:perms %}
{% endblock %}

{% block content %}
<div style="text-align: right; padding-right: 20px;">
	<form action="" method="GET">
		{% for field in form %}
		{{ field.label_tag }}
		{{ field }}
		{% endfor %}
		<br/>
		<input type="submit" value="Osveži" />
	</form>
</div>
<center>
	<h2>Tabela igrača ({{ game_name }})</h2>

	<table class="tablesorter" id="mainTable" width="50%">
		<thead>
			<tr>
				<th width="70px">Mesto</th>			
				<th>Igrač</th>
				<th width="50px">Poeni</th>
			</tr>			
		</thead>
		<tbody>
		{% for user in users %}
			<tr>
				<td id="id{{forloop.counter}}">{{ forloop.counter }}.</td>
				<td id="user{{forloop.counter}}">{{ user|pretty_user }}</td>
				<td>
					{% if game_type_id == 1 %}
					{{ user.chess_points }}
					{% elif game_type_id == 2 %}
					{{ user.tf_points }}
					{% elif game_type_id == 3 %}
					{{ user.football_points }}
					{% elif game_type_id == 4 %}
					{{ user.basket_points }}
					{% else %}
					{% endif %}
				</td>
			</tr>
			{% endfor %}
			</tbody>
	</table>
</center>
{% endblock %}
